package org.hero.web;

import org.hero.dao.NewsDao;
import org.hero.entity.*;
import org.hero.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by xuzhongyao on 16/8/2.
 */
@Controller
public class HomeController {

    @Autowired
    private UserService userService;

    @Autowired
    NewsDao newsDao;


    @RequestMapping("/home")
    @ResponseBody
    public Object bbs(Model model) {
        //List<QunSummary> list = userService.findSix("");
        List<OptionStation> areaNames = newsDao.getAllAreaName();
        Map<String,Object> map = new HashMap<String, Object>();
        //map.put("list", list);
        map.put("areaNames", areaNames);
        return map;
    }

    @ResponseBody
    @RequestMapping("/showMiddle")
    public Object showMiddle(Model model, String suggest) {
        List<CommunityInformation> list2 = userService.findAllCommunityInformation(suggest);
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("list", list2);
        return map;
    }

    @ResponseBody
    @RequestMapping("/list")
    public QunSummary list(ModelMap modelMap, String suggest) {
        QunSummary list = userService.findSix(suggest);
        return list;
    }

    /**
     * 小区错误饼图
     *
     * @param modelMap
     * @return
     */
    @ResponseBody
    @RequestMapping("/cakebill")
    public List<UploadData> cakebill(ModelMap modelMap, String suggest) {
        Integer num1 = userService.selectNum1(suggest);
        Integer num2 = userService.selectNum2(suggest);
        ArrayList list0 = new ArrayList();
        list0.add(num1);
        list0.add(num2);
        return list0;
    }

    @ResponseBody
    @RequestMapping("/mlist")
    public List<UploadData> mlist(ModelMap modelMap, String suggest) {
        List<UploadData> list = userService.selectNum(suggest);
        return list;
    }

    @ResponseBody
    @RequestMapping("/findweek")
    public List<QunSummary> findweek(ModelMap modelMap, String suggest) {
        List<QunSummary> list = userService.findweek(suggest);
        Collections.reverse(list);
        return list;
    }

    @ResponseBody
    @RequestMapping("/findcake")
    public List<QunSummary> findcake(ModelMap modelMap, String suggest) {
        List<QunSummary> list = userService.selectCake(suggest);
        return list;
    }




}
